// $ANTLR 3.3 Nov 30, 2010 12:50:56 /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g 2012-03-29 09:31:30
 package org.rx; 

import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;


import org.antlr.runtime.tree.*;

public class DispatcherParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "METHODS", "METHOD", "DEF", "SIGNATURE", "TYPE", "TEMPLATENAME", "NAME", "MODIFIER", "SPACE", "LINEBREAK", "WS", "COMMENT", "WORD_NAME", "BASIC_NAME", "TNAME", "'{'", "';'", "'}'", "':'", "'('", "','", "')'"
    };
    public static final int EOF=-1;
    public static final int T__19=19;
    public static final int T__20=20;
    public static final int T__21=21;
    public static final int T__22=22;
    public static final int T__23=23;
    public static final int T__24=24;
    public static final int T__25=25;
    public static final int METHODS=4;
    public static final int METHOD=5;
    public static final int DEF=6;
    public static final int SIGNATURE=7;
    public static final int TYPE=8;
    public static final int TEMPLATENAME=9;
    public static final int NAME=10;
    public static final int MODIFIER=11;
    public static final int SPACE=12;
    public static final int LINEBREAK=13;
    public static final int WS=14;
    public static final int COMMENT=15;
    public static final int WORD_NAME=16;
    public static final int BASIC_NAME=17;
    public static final int TNAME=18;

    // delegates
    // delegators


        public DispatcherParser(TokenStream input) {
            this(input, new RecognizerSharedState());
        }
        public DispatcherParser(TokenStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        
    protected TreeAdaptor adaptor = new CommonTreeAdaptor();

    public void setTreeAdaptor(TreeAdaptor adaptor) {
        this.adaptor = adaptor;
    }
    public TreeAdaptor getTreeAdaptor() {
        return adaptor;
    }

    public String[] getTokenNames() { return DispatcherParser.tokenNames; }
    public String getGrammarFileName() { return "/Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g"; }


    public static class start_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "start"
    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:13:1: start : ( method_def )+ -> ^( METHODS ( method_def )+ ) ;
    public final DispatcherParser.start_return start() throws RecognitionException {
        DispatcherParser.start_return retval = new DispatcherParser.start_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        DispatcherParser.method_def_return method_def1 = null;


        RewriteRuleSubtreeStream stream_method_def=new RewriteRuleSubtreeStream(adaptor,"rule method_def");
        try {
            // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:13:6: ( ( method_def )+ -> ^( METHODS ( method_def )+ ) )
            // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:13:8: ( method_def )+
            {
            // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:13:8: ( method_def )+
            int cnt1=0;
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( ((LA1_0>=TEMPLATENAME && LA1_0<=NAME)) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:13:8: method_def
            	    {
            	    pushFollow(FOLLOW_method_def_in_start64);
            	    method_def1=method_def();

            	    state._fsp--;

            	    stream_method_def.add(method_def1.getTree());

            	    }
            	    break;

            	default :
            	    if ( cnt1 >= 1 ) break loop1;
                        EarlyExitException eee =
                            new EarlyExitException(1, input);
                        throw eee;
                }
                cnt1++;
            } while (true);



            // AST REWRITE
            // elements: method_def
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 13:20: -> ^( METHODS ( method_def )+ )
            {
                // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:13:23: ^( METHODS ( method_def )+ )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(METHODS, "METHODS"), root_1);

                if ( !(stream_method_def.hasNext()) ) {
                    throw new RewriteEarlyExitException();
                }
                while ( stream_method_def.hasNext() ) {
                    adaptor.addChild(root_1, stream_method_def.nextTree());

                }
                stream_method_def.reset();

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;
            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "start"

    public static class method_def_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "method_def"
    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:15:1: method_def : (t= TEMPLATENAME )? n= NAME s= signature rtype '{' ( definition ( ';' )? )* '}' ( ';' )? -> ^( METHOD[$n.text] rtype $s ( $t)? ( definition )* ) ;
    public final DispatcherParser.method_def_return method_def() throws RecognitionException {
        DispatcherParser.method_def_return retval = new DispatcherParser.method_def_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token t=null;
        Token n=null;
        Token char_literal3=null;
        Token char_literal5=null;
        Token char_literal6=null;
        Token char_literal7=null;
        DispatcherParser.signature_return s = null;

        DispatcherParser.rtype_return rtype2 = null;

        DispatcherParser.definition_return definition4 = null;


        Object t_tree=null;
        Object n_tree=null;
        Object char_literal3_tree=null;
        Object char_literal5_tree=null;
        Object char_literal6_tree=null;
        Object char_literal7_tree=null;
        RewriteRuleTokenStream stream_21=new RewriteRuleTokenStream(adaptor,"token 21");
        RewriteRuleTokenStream stream_20=new RewriteRuleTokenStream(adaptor,"token 20");
        RewriteRuleTokenStream stream_NAME=new RewriteRuleTokenStream(adaptor,"token NAME");
        RewriteRuleTokenStream stream_19=new RewriteRuleTokenStream(adaptor,"token 19");
        RewriteRuleTokenStream stream_TEMPLATENAME=new RewriteRuleTokenStream(adaptor,"token TEMPLATENAME");
        RewriteRuleSubtreeStream stream_definition=new RewriteRuleSubtreeStream(adaptor,"rule definition");
        RewriteRuleSubtreeStream stream_rtype=new RewriteRuleSubtreeStream(adaptor,"rule rtype");
        RewriteRuleSubtreeStream stream_signature=new RewriteRuleSubtreeStream(adaptor,"rule signature");
        try {
            // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:15:12: ( (t= TEMPLATENAME )? n= NAME s= signature rtype '{' ( definition ( ';' )? )* '}' ( ';' )? -> ^( METHOD[$n.text] rtype $s ( $t)? ( definition )* ) )
            // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:15:14: (t= TEMPLATENAME )? n= NAME s= signature rtype '{' ( definition ( ';' )? )* '}' ( ';' )?
            {
            // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:15:15: (t= TEMPLATENAME )?
            int alt2=2;
            int LA2_0 = input.LA(1);

            if ( (LA2_0==TEMPLATENAME) ) {
                alt2=1;
            }
            switch (alt2) {
                case 1 :
                    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:15:15: t= TEMPLATENAME
                    {
                    t=(Token)match(input,TEMPLATENAME,FOLLOW_TEMPLATENAME_in_method_def84);  
                    stream_TEMPLATENAME.add(t);


                    }
                    break;

            }

            n=(Token)match(input,NAME,FOLLOW_NAME_in_method_def89);  
            stream_NAME.add(n);

            pushFollow(FOLLOW_signature_in_method_def93);
            s=signature();

            state._fsp--;

            stream_signature.add(s.getTree());
            pushFollow(FOLLOW_rtype_in_method_def95);
            rtype2=rtype();

            state._fsp--;

            stream_rtype.add(rtype2.getTree());
            char_literal3=(Token)match(input,19,FOLLOW_19_in_method_def98);  
            stream_19.add(char_literal3);

            // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:15:60: ( definition ( ';' )? )*
            loop4:
            do {
                int alt4=2;
                int LA4_0 = input.LA(1);

                if ( ((LA4_0>=NAME && LA4_0<=MODIFIER)) ) {
                    alt4=1;
                }


                switch (alt4) {
            	case 1 :
            	    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:15:61: definition ( ';' )?
            	    {
            	    pushFollow(FOLLOW_definition_in_method_def101);
            	    definition4=definition();

            	    state._fsp--;

            	    stream_definition.add(definition4.getTree());
            	    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:15:72: ( ';' )?
            	    int alt3=2;
            	    int LA3_0 = input.LA(1);

            	    if ( (LA3_0==20) ) {
            	        alt3=1;
            	    }
            	    switch (alt3) {
            	        case 1 :
            	            // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:15:72: ';'
            	            {
            	            char_literal5=(Token)match(input,20,FOLLOW_20_in_method_def103);  
            	            stream_20.add(char_literal5);


            	            }
            	            break;

            	    }


            	    }
            	    break;

            	default :
            	    break loop4;
                }
            } while (true);

            char_literal6=(Token)match(input,21,FOLLOW_21_in_method_def108);  
            stream_21.add(char_literal6);

            // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:15:83: ( ';' )?
            int alt5=2;
            int LA5_0 = input.LA(1);

            if ( (LA5_0==20) ) {
                alt5=1;
            }
            switch (alt5) {
                case 1 :
                    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:15:83: ';'
                    {
                    char_literal7=(Token)match(input,20,FOLLOW_20_in_method_def110);  
                    stream_20.add(char_literal7);


                    }
                    break;

            }



            // AST REWRITE
            // elements: t, s, rtype, definition
            // token labels: t
            // rule labels: retval, s
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleTokenStream stream_t=new RewriteRuleTokenStream(adaptor,"token t",t);
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);
            RewriteRuleSubtreeStream stream_s=new RewriteRuleSubtreeStream(adaptor,"rule s",s!=null?s.tree:null);

            root_0 = (Object)adaptor.nil();
            // 16:4: -> ^( METHOD[$n.text] rtype $s ( $t)? ( definition )* )
            {
                // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:16:7: ^( METHOD[$n.text] rtype $s ( $t)? ( definition )* )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(METHOD, (n!=null?n.getText():null)), root_1);

                adaptor.addChild(root_1, stream_rtype.nextTree());
                adaptor.addChild(root_1, stream_s.nextTree());
                // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:16:34: ( $t)?
                if ( stream_t.hasNext() ) {
                    adaptor.addChild(root_1, stream_t.nextNode());

                }
                stream_t.reset();
                // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:16:38: ( definition )*
                while ( stream_definition.hasNext() ) {
                    adaptor.addChild(root_1, stream_definition.nextTree());

                }
                stream_definition.reset();

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;
            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "method_def"

    public static class rtype_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "rtype"
    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:18:1: rtype : ( ':' t= NAME -> $t | -> TYPE[\"void\"] );
    public final DispatcherParser.rtype_return rtype() throws RecognitionException {
        DispatcherParser.rtype_return retval = new DispatcherParser.rtype_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token t=null;
        Token char_literal8=null;

        Object t_tree=null;
        Object char_literal8_tree=null;
        RewriteRuleTokenStream stream_NAME=new RewriteRuleTokenStream(adaptor,"token NAME");
        RewriteRuleTokenStream stream_22=new RewriteRuleTokenStream(adaptor,"token 22");

        try {
            // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:19:2: ( ':' t= NAME -> $t | -> TYPE[\"void\"] )
            int alt6=2;
            int LA6_0 = input.LA(1);

            if ( (LA6_0==22) ) {
                alt6=1;
            }
            else if ( (LA6_0==19) ) {
                alt6=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 6, 0, input);

                throw nvae;
            }
            switch (alt6) {
                case 1 :
                    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:19:4: ':' t= NAME
                    {
                    char_literal8=(Token)match(input,22,FOLLOW_22_in_rtype143);  
                    stream_22.add(char_literal8);

                    t=(Token)match(input,NAME,FOLLOW_NAME_in_rtype147);  
                    stream_NAME.add(t);



                    // AST REWRITE
                    // elements: t
                    // token labels: t
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    retval.tree = root_0;
                    RewriteRuleTokenStream stream_t=new RewriteRuleTokenStream(adaptor,"token t",t);
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 19:15: -> $t
                    {
                        adaptor.addChild(root_0, stream_t.nextNode());

                    }

                    retval.tree = root_0;
                    }
                    break;
                case 2 :
                    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:20:4: 
                    {

                    // AST REWRITE
                    // elements: 
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 20:4: -> TYPE[\"void\"]
                    {
                        adaptor.addChild(root_0, (Object)adaptor.create(TYPE, "void"));

                    }

                    retval.tree = root_0;
                    }
                    break;

            }
            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "rtype"

    public static class signature_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "signature"
    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:23:1: signature : '(' (t+= NAME ( ',' t+= NAME )* )? ')' -> ^( SIGNATURE ( $t)* ) ;
    public final DispatcherParser.signature_return signature() throws RecognitionException {
        DispatcherParser.signature_return retval = new DispatcherParser.signature_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token char_literal9=null;
        Token char_literal10=null;
        Token char_literal11=null;
        Token t=null;
        List list_t=null;

        Object char_literal9_tree=null;
        Object char_literal10_tree=null;
        Object char_literal11_tree=null;
        Object t_tree=null;
        RewriteRuleTokenStream stream_NAME=new RewriteRuleTokenStream(adaptor,"token NAME");
        RewriteRuleTokenStream stream_23=new RewriteRuleTokenStream(adaptor,"token 23");
        RewriteRuleTokenStream stream_24=new RewriteRuleTokenStream(adaptor,"token 24");
        RewriteRuleTokenStream stream_25=new RewriteRuleTokenStream(adaptor,"token 25");

        try {
            // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:23:10: ( '(' (t+= NAME ( ',' t+= NAME )* )? ')' -> ^( SIGNATURE ( $t)* ) )
            // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:23:12: '(' (t+= NAME ( ',' t+= NAME )* )? ')'
            {
            char_literal9=(Token)match(input,23,FOLLOW_23_in_signature169);  
            stream_23.add(char_literal9);

            // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:23:16: (t+= NAME ( ',' t+= NAME )* )?
            int alt8=2;
            int LA8_0 = input.LA(1);

            if ( (LA8_0==NAME) ) {
                alt8=1;
            }
            switch (alt8) {
                case 1 :
                    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:23:17: t+= NAME ( ',' t+= NAME )*
                    {
                    t=(Token)match(input,NAME,FOLLOW_NAME_in_signature174);  
                    stream_NAME.add(t);

                    if (list_t==null) list_t=new ArrayList();
                    list_t.add(t);

                    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:23:25: ( ',' t+= NAME )*
                    loop7:
                    do {
                        int alt7=2;
                        int LA7_0 = input.LA(1);

                        if ( (LA7_0==24) ) {
                            alt7=1;
                        }


                        switch (alt7) {
                    	case 1 :
                    	    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:23:26: ',' t+= NAME
                    	    {
                    	    char_literal10=(Token)match(input,24,FOLLOW_24_in_signature177);  
                    	    stream_24.add(char_literal10);

                    	    t=(Token)match(input,NAME,FOLLOW_NAME_in_signature181);  
                    	    stream_NAME.add(t);

                    	    if (list_t==null) list_t=new ArrayList();
                    	    list_t.add(t);


                    	    }
                    	    break;

                    	default :
                    	    break loop7;
                        }
                    } while (true);


                    }
                    break;

            }

            char_literal11=(Token)match(input,25,FOLLOW_25_in_signature187);  
            stream_25.add(char_literal11);



            // AST REWRITE
            // elements: t
            // token labels: 
            // rule labels: retval
            // token list labels: t
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleTokenStream stream_t=new RewriteRuleTokenStream(adaptor,"token t", list_t);
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 23:46: -> ^( SIGNATURE ( $t)* )
            {
                // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:23:49: ^( SIGNATURE ( $t)* )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(SIGNATURE, "SIGNATURE"), root_1);

                // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:23:61: ( $t)*
                while ( stream_t.hasNext() ) {
                    adaptor.addChild(root_1, stream_t.nextNode());

                }
                stream_t.reset();

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;
            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "signature"

    public static class definition_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "definition"
    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:25:1: definition : (n= NAME '(' l= NAME ',' r= NAME ')' -> ^( DEF[$n] $l $r) | m= MODIFIER -> $m);
    public final DispatcherParser.definition_return definition() throws RecognitionException {
        DispatcherParser.definition_return retval = new DispatcherParser.definition_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token n=null;
        Token l=null;
        Token r=null;
        Token m=null;
        Token char_literal12=null;
        Token char_literal13=null;
        Token char_literal14=null;

        Object n_tree=null;
        Object l_tree=null;
        Object r_tree=null;
        Object m_tree=null;
        Object char_literal12_tree=null;
        Object char_literal13_tree=null;
        Object char_literal14_tree=null;
        RewriteRuleTokenStream stream_NAME=new RewriteRuleTokenStream(adaptor,"token NAME");
        RewriteRuleTokenStream stream_23=new RewriteRuleTokenStream(adaptor,"token 23");
        RewriteRuleTokenStream stream_24=new RewriteRuleTokenStream(adaptor,"token 24");
        RewriteRuleTokenStream stream_25=new RewriteRuleTokenStream(adaptor,"token 25");
        RewriteRuleTokenStream stream_MODIFIER=new RewriteRuleTokenStream(adaptor,"token MODIFIER");

        try {
            // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:26:2: (n= NAME '(' l= NAME ',' r= NAME ')' -> ^( DEF[$n] $l $r) | m= MODIFIER -> $m)
            int alt9=2;
            int LA9_0 = input.LA(1);

            if ( (LA9_0==NAME) ) {
                alt9=1;
            }
            else if ( (LA9_0==MODIFIER) ) {
                alt9=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 9, 0, input);

                throw nvae;
            }
            switch (alt9) {
                case 1 :
                    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:26:4: n= NAME '(' l= NAME ',' r= NAME ')'
                    {
                    n=(Token)match(input,NAME,FOLLOW_NAME_in_definition208);  
                    stream_NAME.add(n);

                    char_literal12=(Token)match(input,23,FOLLOW_23_in_definition210);  
                    stream_23.add(char_literal12);

                    l=(Token)match(input,NAME,FOLLOW_NAME_in_definition215);  
                    stream_NAME.add(l);

                    char_literal13=(Token)match(input,24,FOLLOW_24_in_definition217);  
                    stream_24.add(char_literal13);

                    r=(Token)match(input,NAME,FOLLOW_NAME_in_definition221);  
                    stream_NAME.add(r);

                    char_literal14=(Token)match(input,25,FOLLOW_25_in_definition223);  
                    stream_25.add(char_literal14);



                    // AST REWRITE
                    // elements: r, l
                    // token labels: r, l
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    retval.tree = root_0;
                    RewriteRuleTokenStream stream_r=new RewriteRuleTokenStream(adaptor,"token r",r);
                    RewriteRuleTokenStream stream_l=new RewriteRuleTokenStream(adaptor,"token l",l);
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 26:39: -> ^( DEF[$n] $l $r)
                    {
                        // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:26:42: ^( DEF[$n] $l $r)
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(DEF, n), root_1);

                        adaptor.addChild(root_1, stream_l.nextNode());
                        adaptor.addChild(root_1, stream_r.nextNode());

                        adaptor.addChild(root_0, root_1);
                        }

                    }

                    retval.tree = root_0;
                    }
                    break;
                case 2 :
                    // /Users/morandat/workspace/reactor-tools/src/org/rx/Dispatcher.g:27:4: m= MODIFIER
                    {
                    m=(Token)match(input,MODIFIER,FOLLOW_MODIFIER_in_definition244);  
                    stream_MODIFIER.add(m);



                    // AST REWRITE
                    // elements: m
                    // token labels: m
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    retval.tree = root_0;
                    RewriteRuleTokenStream stream_m=new RewriteRuleTokenStream(adaptor,"token m",m);
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 27:15: -> $m
                    {
                        adaptor.addChild(root_0, stream_m.nextNode());

                    }

                    retval.tree = root_0;
                    }
                    break;

            }
            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "definition"

    // Delegated rules


 

    public static final BitSet FOLLOW_method_def_in_start64 = new BitSet(new long[]{0x0000000000000602L});
    public static final BitSet FOLLOW_TEMPLATENAME_in_method_def84 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_NAME_in_method_def89 = new BitSet(new long[]{0x0000000000800000L});
    public static final BitSet FOLLOW_signature_in_method_def93 = new BitSet(new long[]{0x0000000000480000L});
    public static final BitSet FOLLOW_rtype_in_method_def95 = new BitSet(new long[]{0x0000000000080000L});
    public static final BitSet FOLLOW_19_in_method_def98 = new BitSet(new long[]{0x0000000000200C00L});
    public static final BitSet FOLLOW_definition_in_method_def101 = new BitSet(new long[]{0x0000000000300C00L});
    public static final BitSet FOLLOW_20_in_method_def103 = new BitSet(new long[]{0x0000000000200C00L});
    public static final BitSet FOLLOW_21_in_method_def108 = new BitSet(new long[]{0x0000000000100002L});
    public static final BitSet FOLLOW_20_in_method_def110 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_22_in_rtype143 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_NAME_in_rtype147 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_23_in_signature169 = new BitSet(new long[]{0x0000000002000400L});
    public static final BitSet FOLLOW_NAME_in_signature174 = new BitSet(new long[]{0x0000000003000000L});
    public static final BitSet FOLLOW_24_in_signature177 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_NAME_in_signature181 = new BitSet(new long[]{0x0000000003000000L});
    public static final BitSet FOLLOW_25_in_signature187 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_NAME_in_definition208 = new BitSet(new long[]{0x0000000000800000L});
    public static final BitSet FOLLOW_23_in_definition210 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_NAME_in_definition215 = new BitSet(new long[]{0x0000000001000000L});
    public static final BitSet FOLLOW_24_in_definition217 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_NAME_in_definition221 = new BitSet(new long[]{0x0000000002000000L});
    public static final BitSet FOLLOW_25_in_definition223 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_MODIFIER_in_definition244 = new BitSet(new long[]{0x0000000000000002L});

}